package com.hytc.mymall;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hytc.mymall.activity.HomeActivity;
import com.hytc.mymall.activity.login.LoginActivity;
import com.hytc.mymall.activity.OnePointMallActivity;
import com.hytc.mymall.adapter.MainBottomAdapter;
import com.hytc.mymall.application.ActivityManager;
import com.hytc.mymall.base.BaseFragmentActivity;
import com.hytc.mymall.base.BasePager;
import com.hytc.mymall.bean.HomeInfoBean;
import com.hytc.mymall.bean.LoginBean;
import com.hytc.mymall.bean.MainNoticeBean;
import com.hytc.mymall.braodcastreciver.HeadIconChangeReceiver;
import com.hytc.mymall.http.OkHttpClientManager;
import com.hytc.mymall.http.StringPopCallBack;
import com.hytc.mymall.pager.pager1;
import com.hytc.mymall.pager.pager2;
import com.hytc.mymall.pager.pager3;
import com.hytc.mymall.pager.pager4;
import com.hytc.mymall.pager.pager5;
import com.hytc.mymall.pager.pager6;
import com.hytc.mymall.pager.pager7;
import com.hytc.mymall.pop.MainMoretPop;
import com.hytc.mymall.pop.NoticePop;
import com.hytc.mymall.utils.BaseTools;
import com.hytc.mymall.utils.GsonUtils;
import com.hytc.mymall.view.CircleImageView;
import com.hytc.mymall.view.HorizontalListView;
import com.hytc.mymall.view.JazzyViewPager;
import com.hytc.mymall.view.OutlineContainer;
import com.hytc.mymall.view.ViewPagerScroller;
import com.hytc.mymall.weight.MarqueTextView;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class MainActivity extends BaseFragmentActivity
  implements OnClickListener, HeadIconChangeReceiver.HeadChangeInteraction, ViewPager.OnPageChangeListener, OnItemClickListener
{
  private MainAdapter adapter;
  private HorizontalListView hlv;
  private List<HomeInfoBean.Home11> home11List;
  private HomeInfoBean.Home9 home9;
  private boolean isFromHomeActivity;
  private ImageView iv;
  private ImageView iv2;
  private CircleImageView iv_login;
  private ImageView iv_logo;
  private ImageView iv_pop;
  private JazzyViewPager jvp;
  private LinearLayout ll_main;
  private MarqueTextView mtv;
  private List<HomeInfoBean.Home3> noticeList;
  private NoticePop noticePop;
  private List<BasePager> pagers = new ArrayList();
  private MainMoretPop pop;
  private HeadIconChangeReceiver receiver;
  private RelativeLayout rl_more;
  private RelativeLayout rl_ydkl;
  private RelativeLayout rl_ydlm;
  private RelativeLayout rl_ydsc;
  private TextView tv_username;

  public MainActivity() {
  }

  private void getHomeInfo()
  {
    try
    {
      OkHttpClientManager.getAsyn("http://www.51ydgy.com/appcommon/getHomeInfo", new StringPopCallBack(this, true)
      {
        public void onResponse(String paramAnonymousString)
        {
          try
          {
            HomeInfoBean localHomeInfoBean = GsonUtils.json2Bean(paramAnonymousString, HomeInfoBean.class);
            Log.e("TAG",localHomeInfoBean.toString());
            if ((localHomeInfoBean != null) && (localHomeInfoBean.code.equals("0")))
            {
             noticeList = localHomeInfoBean.data.home3;
             initCenterViewpager(localHomeInfoBean.data);
             initNotice(MainActivity.this.noticeList);
              HomeInfoBean.Home10 localHome10 = localHomeInfoBean.data.home10;
              if ((localHome10.content != null) && (localHome10.content.state == 0) && (!MainActivity.this.isFromHomeActivity)) {
                MainActivity.this.getNoticeInfo();
              }
              if ((localHomeInfoBean.data.home11 != null) && (localHomeInfoBean.data.home11.size() > 0))
              {
               home11List = new ArrayList();
                for (int i = 0;i <= localHomeInfoBean.data.home11.size(); i++)
                {
                  if (i <= localHomeInfoBean.data.home11.size())
                  {
                    HomeInfoBean.Home11 localHome11 = localHomeInfoBean.data.home11.get(i);
                    Log.e("TAG",localHome11.state+"");
                    if (localHome11.state == 0) {
                      home11List.add(localHome11);
                      hlv.setAdapter(new MainBottomAdapter(MainActivity.this, home11List));
                    }
                  }
                }
              }
            }
            return;
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
            Log.e("TAG1",localException.toString());
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      Log.e("TAG2",localException.toString());
    }
  }
  
  private void getNoticeInfo()
  {
    OkHttpClientManager.getAsyn("http://www.51ydgy.com/appcommon/getHomeNotice", new StringPopCallBack(this, false)
    {
      public void onResponse(String paramAnonymousString)
      {
        MainNoticeBean localMainNoticeBean = (MainNoticeBean) GsonUtils.json2Bean(paramAnonymousString, MainNoticeBean.class);
        String str1 = localMainNoticeBean.code;
        if ((!TextUtils.isEmpty(str1)) && (str1.equals("0")))
        {
          MainNoticeBean.Data_MainNotice localData_MainNotice = localMainNoticeBean.data;
          if (localData_MainNotice != null)
          {
            String str2 = localData_MainNotice.noticetitle;
            String str3 = localData_MainNotice.content;
            String str4 = localData_MainNotice.fromname;
            String str5 = BaseTools.getData2(localData_MainNotice.createtime);
            MainActivity.this.noticePop = new NoticePop(MainActivity.this, MainActivity.this.ll_main, str2, str3, str4, str5, MainActivity.this.iv_pop.getLeft(), iv.getTop());
            MainActivity.this.noticePop.showPop();
          }
        }
      }
    });
  }
  
  private void initCenterViewpager(HomeInfoBean.HomeInfo paramHomeInfo)
  {
    this.pagers.add(new pager1(this, R.layout.pager_page1, paramHomeInfo));
    this.pagers.add(new pager2(this, R.layout.pager_page2, paramHomeInfo));
    this.pagers.add(new pager3(this, R.layout.pager_page3, paramHomeInfo, "page3"));
    this.pagers.add(new pager4(this, R.layout.pager_page4, paramHomeInfo));
    this.pagers.add(new pager5(this, R.layout.pager_page5, paramHomeInfo));
    this.pagers.add(new pager3(this, R.layout.pager_page3, paramHomeInfo, "page6"));
    this.pagers.add(new pager6(this, R.layout.pager_page6, paramHomeInfo));
    this.pagers.add(new pager7(this, R.layout.pager_page7, paramHomeInfo));
    ViewPagerScroller localViewPagerScroller = new ViewPagerScroller(this);
    localViewPagerScroller.setScrollDuration(1000);
    this.adapter = new MainAdapter();
    this.jvp.setAdapter(this.adapter);
    localViewPagerScroller.initViewPagerScroll(this.jvp);
    this.jvp.setOnPageChangeListener(this);
  }
  
  private void initData()
  {
    LoginBean.Data_Login localData_Login = ActivityManager.loginBean;
    if (localData_Login != null)
    {
      String str = localData_Login.picture;
      Glide.with(this).load(str).error(R.color.red).into(this.iv_login);
      this.tv_username.setText(localData_Login.username);
    }
    try
    {
      getHomeInfo();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
  
  private void initMorePop()
  {
    this.pop = new MainMoretPop(this, this.iv_pop);
  }
  
  private void initNotice(List<HomeInfoBean.Home3> paramList)
  {
    String str = null;
    Iterator localIterator = null;
    if (paramList.size() > 0)
    {
      str = "";
      localIterator = paramList.iterator();
    }
    for (;;)
    {
      if (!localIterator.hasNext())
      {
        this.mtv.setText(str);
        return;
      }
      HomeInfoBean.Home3 localHome3 = (HomeInfoBean.Home3)localIterator.next();
      str = str + "                               " + localHome3.title;
    }
  }
  
  private void initView()
  {
      ll_main = ((LinearLayout)findViewById(R.id.ll_main));
    LinearLayout localLinearLayout = (LinearLayout)findViewById(R.id.ll_main_head);
    //头像
      iv_login = ((CircleImageView)findViewById(R.id.civ_main_head));
//    this.tv_username = ((TextView)$(2131099851));
    RelativeLayout localRelativeLayout = (RelativeLayout)findViewById(R.id.rl_main_notices);
    this.mtv = ((MarqueTextView)findViewById(R.id.mtv_main_news));
    this.iv_pop = ((ImageView)findViewById(R.id.iv_more));
    this.jvp = ((JazzyViewPager)findViewById(R.id.jvp_main));
    iv = ((ImageView)findViewById(R.id.iv_main_center));
    this.iv2 = ((ImageView)findViewById(R.id.iv2_main_center));
    this.iv_logo = ((ImageView)findViewById(R.id.iv_main_logo));
    this.rl_more = ((RelativeLayout)findViewById(R.id.rl_more));
    hlv = ((HorizontalListView)findViewById(R.id.hlv_main));
    localLinearLayout.setOnClickListener(this);
    localRelativeLayout.setOnClickListener(this);
    iv_logo.setOnClickListener(this);
    rl_more.setOnClickListener(this);
    this.hlv.setOnItemClickListener(this);
  }
  
  public void onClick(View paramView) {
    switch (paramView.getId()) {
//    default:
//      return;
//    case 2131099849:
    case R.id.ll_main_head:
      if (ActivityManager.loginBean != null)
      {
        Intent localIntent2 = new Intent(this, HomeActivity.class);
        localIntent2.putExtra("selection", 3);
        startActivity(localIntent2);
        return;
      }
      startActivity(new Intent(this, LoginActivity.class));
      return;
    case R.id.rl_more:
      this.pop.showPop();
      return;
//    }
//    Intent localIntent1 = new Intent(this, UnionWelfareRankActivity.class);
//    localIntent1.putExtra("isRank", false);
//    startActivity(localIntent1);
    }
  }
  
  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(R.layout.activity_main);
    initView();
    initData();
    initMorePop();
    this.isFromHomeActivity = getIntent().getBooleanExtra("fromehomeactivity", false);
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("com.sz.ydgy.headicon.change");
    this.receiver = new HeadIconChangeReceiver();
    registerReceiver(this.receiver, localIntentFilter);
    this.receiver.setHeadIconListener(this);
  }
  
  protected void onDestroy()
  {
    super.onDestroy();
    unregisterReceiver(this.receiver);
  }
  
  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    HomeInfoBean.Home11 localHome11 = (HomeInfoBean.Home11)this.home11List.get(paramInt);
    Intent localIntent = new Intent(this, OnePointMallActivity.class);
    localIntent.putExtra("type", localHome11.remark);
    localIntent.putExtra("host", localHome11.url);
    startActivity(localIntent);
  }
  
  public void onPageScrollStateChanged(int paramInt) {}
  
  public void onPageScrolled(int paramInt1, float paramFloat, int paramInt2)
  {
    int i = this.iv.getMeasuredWidth();
    int j = BaseTools.getWindowsWidth(this);
    int k = (int)(paramFloat * (1.0D * j / 3.0D) + paramInt1 * (j / 3));
    this.iv2.setX(-i + k % j);
    this.iv.setX(k % j);
  }
  
  public void onPageSelected(int paramInt)
  {
    this.jvp.currentPostion = paramInt;
  }
  
  protected void onPause()
  {
    super.onPause();
    this.jvp.handler.removeCallbacksAndMessages(null);
  }
  
  protected void onResume()
  {
    super.onResume();
    ActivityManager.getInstance().SingleActivity(this);
    LoginBean.Data_Login localData_Login = ActivityManager.loginBean;
    if (localData_Login != null)
    {
      Glide.with(this).load(localData_Login.picture).error(R.color.red).into(this.iv_login);
      this.tv_username.setText(localData_Login.username);
    }
    this.jvp.startRoll();
  }
  
  protected void onStop()
  {
    super.onStop();
    this.jvp.handler.removeCallbacksAndMessages(null);
  }
  
  public void setHeadIcon(String paramString)
  {
    String str = paramString;
    Glide.with(this).load(str).error(R.color.red).into(this.iv_login);
  }
  
  public void setText() {}
  
  public void setUsername(String paramString)
  {
    this.tv_username.setText(paramString);
  }
  
  private class MainAdapter
    extends PagerAdapter
  {
    private MainAdapter() {}
    
    public void destroyItem(ViewGroup paramViewGroup, int paramInt, Object paramObject)
    {
      paramViewGroup.removeView(MainActivity.this.jvp.findViewFromObject(paramInt));
    }
    
    public int getCount()
    {
      return 8;
    }
    
    public Object instantiateItem(ViewGroup paramViewGroup, int paramInt)
    {
      paramViewGroup.addView(((BasePager)MainActivity.this.pagers.get(paramInt)).rootView);
      MainActivity.this.jvp.setObjectForPosition(((BasePager)MainActivity.this.pagers.get(paramInt)).rootView, paramInt);
      ((BasePager)MainActivity.this.pagers.get(paramInt)).rootView.setOnTouchListener(new OnTouchListener()
      {
        private long endTime;
        private int endX;
        private long startTime;
        private int startX;
        
        public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent) {
            MainActivity.this.jvp.handler.removeCallbacksAndMessages(null);
            this.startTime = System.currentTimeMillis();
            this.startX = ((int)paramAnonymousMotionEvent.getX());
            MainActivity.this.jvp.startRoll();
            this.endTime = System.currentTimeMillis();
            this.endX = ((int)paramAnonymousMotionEvent.getX());
            if (this.startX == this.endX) {
              MainActivity.this.jvp.startRoll();
              return false;
            }

          return true;
        }
      });
      ((BasePager)MainActivity.this.pagers.get(paramInt)).initData();
      return ((BasePager)MainActivity.this.pagers.get(paramInt)).rootView;
    }
    
    public boolean isViewFromObject(View paramView, Object paramObject)
    {
      if ((paramView instanceof OutlineContainer)) {
        if (((OutlineContainer)paramView).getChildAt(0) != paramObject) {}
      }
      while (paramView == paramObject)
      {
        return true;
//        return false;
      }
      return false;
    }
  }
}



/* Location:           C:\Users\Joker\Desktop\classes_dex2jar.jar

 * Qualified Name:     com.sz.ydgy.activity.MainActivity

 * JD-Core Version:    0.7.0.1

 */